#pragma once
#include "IPhysics.h"
#include "Vector2f.h"

class CShapeRectangle;
class CShapeCircle;


class CPhysics: public IPhysics
{
public:
	int m_oneMeterIsInPixels;
	long m_currentTime;
	long m_pauseTime;
	long m_timeStartPause;

	bool m_bPause;

public:
	CPhysics(void);
	~CPhysics(void);

	IShape* createRectangle(int width, int height);
	IShape* createCircle(int radius);

	int meterToPixel(const float meter);
	float pixelToMeter(const int pixel);

	void doUpdate();
	void pauseSimulation(bool bPause);
	
	void fillQuadTree(void);


private:
	IShape* checkCollision(IShape* entity);
	bool checkCollisionBetweenRectangle(CShapeRectangle* entity1, CShapeRectangle* entity2);
	bool checkCollisionBetweenRectangleAndCircle(CShapeRectangle* rectangle, CShapeCircle* circle);
	bool checkCollisionBetweenCircles(CShapeCircle* circle1, CShapeCircle* circle2);

	void polygonProjection(const CVector2f& projectionLine, const CVector2f* boundingBox, float* min, float* max);
	void circleProjection(const CVector2f& projectionLine, const CVector2f& position, float radius, float* min, float* max);

	bool checkOverlap(float a1, float a2, float b1, float b2);
	float getMaximum(float a, float b);
	float getMinimum(float a, float b);

	void displayCollisionReport(const IShape* entity1, const IShape* entity2);

	bool getCollisionPointBetweenRectangles(CShapeRectangle* entity, CShapeRectangle* entity2);
	void getCollisionPointBetweenRectangleAndCircle(CShapeRectangle* rectangle, CShapeCircle* circle);
	void getCollisionPointBetweenCircles(CShapeCircle* circleOne, CShapeCircle* circleTwo);


	void getClosestEdgeOfPoint(CVector2f* bb, CVector2f point, int* idPoint1, int* idPoint2);

	void calculateOBBAndPointInLocalAxis(CVector2f* bb, CVector2f point, CVector2f* newBB, CVector2f* newPoint);
	void calculatePointInGlobalAxis(CVector2f* bb, CVector2f point, CVector2f* newPoint);



	
};
